<template>
  <view>
    <view class="wrap">
      <view class="u-tabs-box">
        <up-tabs activeColor="#f29100" ref="tabs" :list="list" :current="current" @change="change"
                 :is-scroll="false" swiperWidth="750"></up-tabs>
      </view>
      <swiper class="swiper-box" :current="swiperCurrent" @transition="transition"
              @animationfinish="animationfinish">
        <swiper-item class="swiper-item">
          <scroll-view scroll-y style="height: 100%;width: 100%;" @scrolltolower="reachBottom">
            <view class="page-box">
              <view class="order" v-for="(res, index) in orderList[0]" :key="res.id">
                <view class="top">
                  <view class="left">
                    <up-tag text="自取" color="#fff" type="warning"></up-tag>
                    <view class="store">{{ res.store }}</view>
                    <up-icon name="arrow-right" color="rgb(203,203,203)" :size="26"></up-icon>
                  </view>
                  <view class="right">{{ res.deal }}</view>
                </view>
                <scroll-view class="scroll-view_H" scroll-x="true" @scroll="scroll" scroll-left="120">
                  <view class="item">
                    <view class="goods-box" v-for="(item, index) in res.goodsList" :key="index">
                      <view>
                        <view class="left">
                          <image :src="item.goodsUrl" mode="aspectFill"></image>
                        </view>
                        <view class="content">
                          <view class="title u-line-1">{{ item.title }}</view>
                        </view>
                      </view>

                    </view>

                  </view>
                </scroll-view>


                <view class="price-box">
                  <view class="time">2024-09-09 12:12:12</view>
                  <view class="total">
                    共{{ totalNum(res.goodsList) }}件
                    <text class="total-price">
                      ￥{{ priceInt(totalPrice(res.goodsList)) }}.
                      <text class="decimal">{{ priceDecimal(totalPrice(res.goodsList)) }}</text>
                    </text>
                  </view>
                </view>

                <view class="bottom">
                  <view class="more">
                    <up-icon name="more-dot-fill" color="rgb(203,203,203)"></up-icon>
                  </view>

                  <view class="evaluate btn">再来一单</view>
                </view>
              </view>
              <up-loadmore :status="loadStatus[0]" bgColor="#f2f2f2"></up-loadmore>
            </view>
          </scroll-view>
        </swiper-item>
        <swiper-item class="swiper-item">
          <view class="u-tabs-box">
            <up-tabs activeColor="#f29100" ref="tabs" :list="list2" :current="current" @change="change"
                     :is-scroll="false" swiperWidth="750"></up-tabs>
          </view>
          <scroll-view scroll-y style="height: 100%;width: 100%;" @scrolltolower="reachBottom">
            <view class="page-box">
              <view class="order" v-for="(res, index) in orderList[0]" :key="res.id">
                <view class="top">
                  <view class="left">
                    <up-tag text="自取" color="#fff" type="warning"></up-tag>
                    <view class="store">{{ res.store }}</view>
                    <up-icon name="arrow-right" color="rgb(203,203,203)" :size="26"></up-icon>
                  </view>
                  <view class="right">{{ res.deal }}</view>
                </view>
                <scroll-view class="scroll-view_H" scroll-x="true" @scroll="scroll" scroll-left="120">
                  <view class="item">
                    <view class="goods-box" v-for="(item, index) in res.goodsList" :key="index">
                      <view>
                        <view class="left">
                          <image :src="item.goodsUrl" mode="aspectFill"></image>
                        </view>
                        <view class="content">
                          <view class="title u-line-1">{{ item.title }}</view>
                        </view>
                      </view>

                    </view>

                  </view>
                </scroll-view>


                <view class="price-box">
                  <view class="time">2024-09-09 12:12:12</view>
                  <view class="total">
                    共{{ totalNum(res.goodsList) }}件
                    <text class="total-price">
                      ￥{{ priceInt(totalPrice(res.goodsList)) }}.
                      <text class="decimal">{{ priceDecimal(totalPrice(res.goodsList)) }}</text>
                    </text>
                  </view>
                </view>

                <view class="bottom">
                  <view class="more">
                    <up-icon name="more-dot-fill" color="rgb(203,203,203)"></up-icon>
                  </view>

                  <view class="evaluate btn">再来一单</view>
                </view>
              </view>
              <up-loadmore :status="loadStatus[0]" bgColor="#f2f2f2"></up-loadmore>
            </view>
          </scroll-view>
        </swiper-item>
        <swiper-item class="swiper-item">
          <scroll-view scroll-y style="height: 100%;width: 100%;">
            <view class="page-box">
              <view>
                <view class="centre">
                  <image src="https://cdn.uviewui.com/uview/template/taobao-order.png" mode="">
                  </image>
                  <view class="explain">
                    您还没有相关的订单
                    <view class="tips">可以去看看有那些想买的</view>
                  </view>
                  <view class="btn">随便逛逛</view>
                </view>
              </view>
            </view>
          </scroll-view>
        </swiper-item>
        <swiper-item class="swiper-item">
          <scroll-view scroll-y style="height: 100%;width: 100%;" @scrolltolower="reachBottom">
            <view class="page-box">
              <view class="order" v-for="(res, index) in orderList[3]" :key="res.id">
                <view class="top">
                  <view class="left">
                    <up-icon name="home" :size="30" color="rgb(94,94,94)"></up-icon>
                    <view class="store">{{ res.store }}</view>
                    <up-icon name="arrow-right" color="rgb(203,203,203)" :size="26"></up-icon>
                  </view>
                  <view class="right">{{ res.deal }}</view>
                </view>
                <view class="item" v-for="(item, index) in res.goodsList" :key="index">
                  <view class="left">
                    <image :src="item.goodsUrl" mode="aspectFill"></image>
                  </view>
                  <view class="content">
                    <view class="title u-line-2">{{ item.title }}</view>
                    <view class="type">{{ item.type }}</view>
                    <view class="delivery-time">发货时间 {{ item.deliveryTime }}</view>
                  </view>
                  <view class="right">
                    <view class="price">
                      ￥{{ priceInt(item.price) }}
                      <text class="decimal">.{{ priceDecimal(item.price) }}</text>
                    </view>
                    <view class="number">x{{ item.number }}</view>
                  </view>
                </view>
                <view class="total">
                  共{{ totalNum(res.goodsList) }}件商品 合计:
                  <text class="total-price">
                    ￥{{ priceInt(totalPrice(res.goodsList)) }}.
                    <text class="decimal">{{ priceDecimal(totalPrice(res.goodsList)) }}</text>
                  </text>
                </view>
                <view class="bottom">
                  <view class="more">
                    <up-icon name="more-dot-fill" color="rgb(203,203,203)"></up-icon>
                  </view>
                  <view class="logistics btn">查看物流</view>
                  <view class="exchange btn">卖了换钱</view>
                  <view class="evaluate btn">评价</view>
                </view>
              </view>
              <up-loadmore :status="loadStatus[3]" bgColor="#f2f2f2"></up-loadmore>
            </view>
          </scroll-view>
        </swiper-item>
      </swiper>
    </view>
  </view>
</template>

<script>
export default {
  data() {
    return {
      orderList: [[], [], [], []],
      dataList: [
        {
          id: 1,
          store: "教育路奶茶店",
          deal: "已完成",
          goodsList: [
            {
              goodsUrl: "https://img1.baidu.com/it/u=1047945906,2612051836&fm=253&fmt=auto&app=138&f=JPEG?w=813&h=500",
              title: "珍珠奶茶 ",
              type: "灰色;M",
              deliveryTime: "2024-09-09 12:12:12",
              price: "348.58",
              number: 2,
            },
            {
              goodsUrl: "https://img1.baidu.com/it/u=1047945906,2612051836&fm=253&fmt=auto&app=138&f=JPEG?w=813&h=500",
              title: "【葡萄藤】现货 小清新学院风制服格裙百褶裙女短款百搭日系甜美风原创jk制服女2020新款",
              type: "45cm;S",
              deliveryTime: "付款后30天内发货",
              price: "135.00",
              number: 1,
            }, {
              goodsUrl: "https://img1.baidu.com/it/u=1047945906,2612051836&fm=253&fmt=auto&app=138&f=JPEG?w=813&h=500",
              title: "珍珠奶茶 ",
              type: "灰色;M",
              deliveryTime: "2024-09-09 12:12:12",
              price: "348.58",
              number: 2,
            },
            {
              goodsUrl: "https://img1.baidu.com/it/u=1047945906,2612051836&fm=253&fmt=auto&app=138&f=JPEG?w=813&h=500",
              title: "【葡萄藤】现货 小清新学院风制服格裙百褶裙女短款百搭日系甜美风原创jk制服女2020新款",
              type: "45cm;S",
              deliveryTime: "付款后30天内发货",
              price: "135.00",
              number: 1,
            }, {
              goodsUrl: "https://img1.baidu.com/it/u=1047945906,2612051836&fm=253&fmt=auto&app=138&f=JPEG?w=813&h=500",
              title: "珍珠奶茶 ",
              type: "灰色;M",
              deliveryTime: "2024-09-09 12:12:12",
              price: "348.58",
              number: 2,
            },
            {
              goodsUrl: "https://img1.baidu.com/it/u=1047945906,2612051836&fm=253&fmt=auto&app=138&f=JPEG?w=813&h=500",
              title: "【葡萄藤】现货 小清新学院风制服格裙百褶裙女短款百搭日系甜美风原创jk制服女2020新款",
              type: "45cm;S",
              deliveryTime: "付款后30天内发货",
              price: "135.00",
              number: 1,
            },
          ],
        },
        {
          id: 2,
          store: "教育路奶茶店",
          deal: "已完成",
          goodsList: [
            {
              goodsUrl: "https://img1.baidu.com/it/u=1047945906,2612051836&fm=253&fmt=auto&app=138&f=JPEG?w=813&h=500",
              title: "珍珠奶茶",
              type: "粉色;M",
              deliveryTime: "付款后7天内发货",
              price: "128.05",
              number: 1,
            },
          ],
        },
        {
          id: 3,
          store: "教育路奶茶店",
          deal: "已完成",
          goodsList: [
            {
              goodsUrl: "https://img1.baidu.com/it/u=1047945906,2612051836&fm=253&fmt=auto&app=138&f=JPEG?w=813&h=500",
              title: "珍珠奶茶",
              type: "4K，广色域",
              deliveryTime: "保质5年",
              price: "1998",
              number: 3,
            },
            {
              goodsUrl: "https://img1.baidu.com/it/u=1047945906,2612051836&fm=253&fmt=auto&app=138&f=JPEG?w=813&h=500",
              title: "珍珠奶茶",
              type: "容量大，速冻",
              deliveryTime: "保质5年",
              price: "2354",
              number: 1,
            },
          ],
        },
        {
          id: 4,
          store: "教育路奶茶店",
          deal: "已完成",
          goodsList: [
            {
              goodsUrl: "https://img1.baidu.com/it/u=1047945906,2612051836&fm=253&fmt=auto&app=138&f=JPEG?w=813&h=500",
              title: "珍珠奶茶",
              type: "4K，广色域",
              deliveryTime: "珍藏10年好酒",
              price: "1543",
              number: 3,
            },
            {
              goodsUrl: "https://img1.baidu.com/it/u=1047945906,2612051836&fm=253&fmt=auto&app=138&f=JPEG?w=813&h=500",
              title: "珍珠奶茶",
              type: "一打",
              deliveryTime: "口感好",
              price: "120",
              number: 1,
            },
          ],
        },
        {
          id: 5,
          store: "教育路奶茶店",
          deal: "已完成",
          goodsList: [
            {
              goodsUrl: "https://img1.baidu.com/it/u=1047945906,2612051836&fm=253&fmt=auto&app=138&f=JPEG?w=813&h=500",
              title: "珍珠奶茶",
              type: "识别效率高",
              deliveryTime: "使用方便",
              price: "451",
              number: 9,
            },
          ],
        },
      ],
      list: [{
        name: "当日订单",
      },
        {
          name: "历史订单",
        }, {
          name: "退单",
        },

      ], list2: [{
        name: "全部",
      },
        {
          name: "自取",
        },
        {
          name: "外卖",
        },

      ],
      current: 0,
      swiperCurrent: 0,
      tabsHeight: 0,
      dx: 0,
      loadStatus: ["loadmore", "loadmore", "loadmore", "loadmore"],
    };
  },
  onLoad() {
    this.getOrderList(0);
    this.getOrderList(1);
    this.getOrderList(3);
  },
  computed: {
    // 价格小数
    priceDecimal() {
      return val => {
        if (val !== parseInt(val)) return val.slice(-2);
        else return "00";
      };
    },
    // 价格整数
    priceInt() {
      return val => {
        if (val !== parseInt(val)) return val.split(".")[0];
        else return val;
      };
    },
  },
  methods: {
    reachBottom() {
      // 此tab为空数据
      if (this.current != 2) {
        this.loadStatus.splice(this.current, 1, "loading");
        setTimeout(() => {
          this.getOrderList(this.current);
        }, 1200);
      }
    },
    // 页面数据
    getOrderList(idx) {
      for (let i = 0; i < 5; i++) {
        let index = this.$u.random(0, this.dataList.length - 1);
        let data = JSON.parse(JSON.stringify(this.dataList[index]));
        data.id = this.$u.guid();
        this.orderList[idx].push(data);
      }
      this.loadStatus.splice(this.current, 1, "loadmore");
    },
    // 总价
    totalPrice(item) {
      let price = 0;
      item.map(val => {
        price += parseFloat(val.price);
      });
      return price.toFixed(2);
    },
    // 总件数
    totalNum(item) {
      let num = 0;
      item.map(val => {
        num += val.number;
      });
      return num;
    },
    // tab栏切换
    change(e) {
      this.swiperCurrent = e.index;
      this.getOrderList(e.index);
    },
    transition({ detail: { dx } }) {
      // this.$refs.tabs.setDx(dx);
    },
    animationfinish({ detail: { current } }) {
      this.swiperCurrent = current;
      this.current = current;
    },
  },
};
</script>

<style>
/* #ifndef H5 */
page {
  height: 100%;
  background-color: #f2f2f2;
}

/* #endif */
</style>

<style lang="scss" scoped>
.order {
  width: 710rpx;
  background-color: #ffffff;
  margin: 20rpx auto;
  border-radius: 20rpx;
  box-sizing: border-box;
  padding: 20rpx;
  font-size: 28rpx;

  .top {
    display: flex;
    justify-content: space-between;
    margin-bottom: 10rpx;

    .left {
      display: flex;
      align-items: center;

      .store {
        margin: 0 10rpx;
        font-size: 32rpx;
        font-weight: bold;
      }
    }

    .right {
      color: $u-warning-dark;
    }
  }

  .goods-box {
    display: flex;
  }

  .item {
    display: flex;
    flex-direction: row;
    flex-wrap: nowrap;
    //margin: 20rpx 0 0;

    .left {
      margin-right: 20rpx;

      image {
        width: 150rpx;
        height: 150rpx;
        border-radius: 10rpx;
      }
    }

    .content {
      .title {
        font-size: 28rpx;
        //line-height: 50rpx;
        max-width: 150rpx;
      }

      .type {
        margin: 10rpx 0;
        font-size: 24rpx;
        color: $u-tips-color;
      }

      .delivery-time {
        color: #e5d001;
        font-size: 24rpx;
      }
    }

    .right {
      margin-left: 10rpx;
      padding-top: 20rpx;
      text-align: right;

      .decimal {
        font-size: 24rpx;
        margin-top: 4rpx;
      }

      .number {
        color: $u-tips-color;
        font-size: 24rpx;
      }
    }
  }

  .total {
    //margin-top: 20rpx;
    text-align: right;
    font-size: 24rpx;

    .total-price {
      font-size: 32rpx;
    }
  }

  .bottom {
    display: flex;
    margin-top: 40rpx;
    padding: 0 10rpx;
    justify-content: space-between;
    align-items: center;

    .btn {
      line-height: 52rpx;
      width: 160rpx;
      border-radius: 26rpx;
      border: 2rpx solid $u-border-color;
      font-size: 26rpx;
      text-align: center;
      color: $u-info-dark;
    }

    .evaluate {
      color: $u-warning-dark;
      border-color: $u-warning-dark;
    }
  }
}

.centre {
  text-align: center;
  margin: 200rpx auto;
  font-size: 32rpx;

  image {
    width: 164rpx;
    height: 164rpx;
    border-radius: 50%;
    margin-bottom: 20rpx;
  }

  .tips {
    font-size: 24rpx;
    color: #999999;
    margin-top: 20rpx;
  }

  .btn {
    margin: 80rpx auto;
    width: 200rpx;
    border-radius: 32rpx;
    line-height: 64rpx;
    color: #ffffff;
    font-size: 26rpx;
    background: linear-gradient(270deg, rgba(249, 116, 90, 1) 0%, rgba(255, 158, 1, 1) 100%);
  }
}

.wrap {
  display: flex;
  flex-direction: column;
  height: calc(100vh - var(--window-top));
  width: 100%;
}

.swiper-box {
  flex: 1;
}

.swiper-item {
  height: 100%;
}

.price-box {
  display: flex;
  flex-direction: row;
  justify-content: space-between;
  align-items: center;
}
</style>
